Red Skull, the antagonist, uses the Tesseract (the cube in which the Space Stone is contained) to create superpowered weapons for the Nazis during World War II. At the end of the film, Red Skull holds the Tesseract in his hand, and its power is too much for him to control; he is sent into space through a portal made by the Tesseract's powers. At the end of the film, the Tesseract is in the possession of S.H.I.E.L.D. (a government agency that works with espionage, special law enforcement, and counter-terrorism).
Mar-Vell, a Kree* scientist disguised as a human, harnesses the power of the Tesseract in a government project to create a light-speed engine to be secretly used to assist the Skrulls** in fleeing from Kree warlords. However, during the test flight, Kree soldiers shoot down the ship, and the engine explodes. The energy outburst hits Carol Danvers, an Air Force pilot, and she later learns to control the energy inside of her and becomes Captain Marvel. By the end of the film, the Tesseract is once more in possession of S.H.I.E.L.D.
*The Kree are an advanced militaristic race of (mostly) blue-skinned humanoids from the planet Hala.
**The Skrulls are another advanced race of reptilian humanoids, though they possess shapeshifting abilities. They had their home planet destroyed by the Kree, leaving them to assimilate on other planets, only to be seen as invaders and taken out by the Kree.
The film opens with S.H.I.E.L.D. scientists testing the Tesseract's power in an underground bunker; this causes an anomaly in which Loki is able to come through a portal created by it. The Tesseract is later used to make a machine capable of creating a wormhole over New York City that will allow Thanos' army to invade. However, the Avengers stop the army and destroy the machine. Thor uses the Tesseract to return Loki and himself to Asgard, where Loki will receive his punishment for his crimes. The film ends with the Tesseract on Asgard.
The Tesseract is not introduced in the film until a scene where Loki is in Odin's Treasure Room, and he considers taking it.
In the beginning of the film, it is revealed that Loki did take the Tesseract during the events of Thor Ragnarok, and he give it to Thanos in exchange for sparing Thor's life.